import { createApp } from "vue";
import { createPinia } from "pinia";
import App from "./App.vue";
import router from "./router";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
import * as icons from "@/assets/icons";
import "virtual:uno.css";
import "element-plus/theme-chalk/dark/css-vars.css";
import "./styles/dark/css-vars.scss";
import "./styles/global.scss";
import { permissionDirectives } from "@/utils/permission";
import { useWebSocketStore } from "@/stores/websocket";
import { initAMapApiLoader } from "@vuemap/vue-amap";
import '@vuemap/vue-amap/dist/style.css'
import VxeUITable from 'vxe-table'
import 'vxe-table/lib/style.css'

// 初始化高德地图
initAMapApiLoader({
  key: import.meta.env.VITE_AMAP_KEY,
  securityJsCode: import.meta.env.VITE_AMAP_SECRET,
  version: "2.0",
  plugins: ["AMap.Marker", "AMap.InfoWindow", 'AMap.HawkEye'],
});

const app = createApp(App);

app.use(ElementPlus, { locale: zhCn });

// 全局注册所有 Element Plus 图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

// 注册第三方图标
Object.keys(icons).forEach((icon) => {
  app.component(`myIcon${icon}`, icons[icon as keyof typeof icons]);
});

app.use(createPinia());
app.use(router);

app.use(VxeUITable)

// if (localStorage.getItem("token")) {
//   const wsStore = useWebSocketStore();
//   wsStore.initialize({
//     url: import.meta.env.VITE_WS_URL,
//     autoReconnect: true,
//   });
// }

app.directive("permission", permissionDirectives);

app.mount("#app");
